import requests  # 添加requests库导入
new_books = []

def add_ifo():
    title = input("Enter book title: ")
    author = input("Enter book author: ")
    category = input("Enter book category: ")
    new_books.append({
        "title": title,
        "author": author,
        "category": category
    })
    print(f"Book '{title}' added successfully.")

# 将new_book通过post请求发送到服务器（127.0.0.1：8000/books/create_book），并将new_book作为请求体发送。
def post_book():
    add_ifo()
    response = requests.post("http://127.0.0.1:8000/books/create_book", json=new_books[-1])  # 只发送最新添加的书籍
    print(response.json())

if __name__ == "__main__":  # 确保只有在直接运行该脚本时才执行post_book()函数
    post_book()